package com.zyb.beidada.scoring;

import com.zyb.beidada.common.ErrorCode;
import com.zyb.beidada.exception.BusinessException;
import com.zyb.beidada.exception.ThrowUtils;
import com.zyb.beidada.model.entity.App;
import com.zyb.beidada.model.entity.UserAnswer;
import com.zyb.beidada.model.enums.AppTypeEnum;
import com.zyb.beidada.model.enums.ScoringStrategyEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 十八岁讨厌编程
 * @date 2025/5/6 21:22
 * @PROJECT_NAME beidada-backend
 * @description 编程式策略执行器
 */

@Component
public class ScoringStrategyContext {

    @Resource
    private CustomScoreScoringStrategy customScoreScoringStrategy;

    @Resource
    private CustomTestScoringStrategy customTestScoringStrategy;

    public UserAnswer doScore(List<String> choices, App app) throws Exception {
        AppTypeEnum appTypeEnum = AppTypeEnum.fromValue(app.getAppType());
        ScoringStrategyEnum appScoringStrategyEnum = ScoringStrategyEnum.fromValue(app.getScoringStrategy());
        if (appTypeEnum == null || appScoringStrategyEnum == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "应用配置有误，未找到匹配的策略");
        }
        // 根据不同的应用类别和评分策略，选择对应的策略执行
        switch (appTypeEnum) {
            case SCORE:
                switch (appScoringStrategyEnum) {
                    case CUSTOM:
                        return customScoreScoringStrategy.doScore(choices, app);
                    case AI:
                        break;
                }
                break;
            case TEST:
                switch (appScoringStrategyEnum) {
                    case CUSTOM:
                        return customTestScoringStrategy.doScore(choices, app);
                    case AI:
                        break;
                }
                break;
        }
        throw new BusinessException(ErrorCode.SYSTEM_ERROR, "应用配置有误，未找到匹配的策略");
    }

}
